package com.vsoft.sms_cm;
import java.net.UnknownHostException;
import java.util.HashMap;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.MongoException;

public class testMongodb {
	
	public static void main(String[] args)  
	{
		String 	ip				=	args[0];
		String	dbName	=	args[1];
		PropertyConfigurator.configure("log4j.properties");
		HashMap<String,String> dbConfig	= new HashMap<String,String>();
		dbConfig.put("IP", ip);
		dbConfig.put("DBNAME", dbName);
		Mongodb	mdb		=	new Mongodb();
		Logger vLogger = Logger.getLogger(testMongodb.class);
		try {
			Mongo	m			=	mdb.getMongodb(dbConfig);
			DB	db			=	mdb.getDB(m, dbName);
			vLogger.info("---------------InitSystem-------------");
			long start_time=System.currentTimeMillis();
			vLogger.info("---------------start-------------"+start_time);
			long	count		=	10;//1w
			String collection = "testInsert";
			mdb.insertSample(db, collection, count);
			
			long batch_time=System.currentTimeMillis();
			vLogger.info("---------------insert 1w-------------"+(batch_time-start_time));
			count				=	1000000;//100w
			mdb.insertSample(db, collection, count);
			
			batch_time=System.currentTimeMillis();
			vLogger.info("---------------insert 100w-------------"+(batch_time-start_time));
		} catch (MongoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void  init()
	{
		
	}

}
